package com.sqx.modules.sign.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sqx.common.utils.Result;
import com.sqx.modules.sign.dao.TbSigninRewardDao;
import com.sqx.modules.sign.entity.TbSigninReward;
import com.sqx.modules.sign.service.TbSigninRewardService;
import org.springframework.stereotype.Service;

/**
 * @description：TODO
 * @author： qiao
 * @create： 2024/9/30 11:23
 */
@Service
public class TbSigninRewardServiceImpl extends ServiceImpl<TbSigninRewardDao, TbSigninReward> implements TbSigninRewardService {
    @Override
    public Result addSignInReward(TbSigninReward tbSignInReward) {
        if (tbSignInReward.getId() != null){
            baseMapper.updateById(tbSignInReward);
            return Result.success("修改成功");
        }else {
            baseMapper.insert(tbSignInReward);
            return Result.success();
        }
    }

    @Override
    public Result deleteSignInReward(Long id) {
        TbSigninReward tbSignInReward = baseMapper.selectById(id);
        if (tbSignInReward != null){
            baseMapper.deleteById(id);
            return Result.success("删除成功");
        }
        return Result.error("删除失败");
    }

    @Override
    public Result selectSignInRewardById(Long id) {
        TbSigninReward tbSignInReward = baseMapper.selectById(id);
        if (tbSignInReward != null){
            return Result.success().put("data",tbSignInReward);
        }
        return Result.error("查询失败");
    }

    @Override
    public IPage<TbSigninReward> selectSignInRewardList(Integer page, Integer limit, TbSigninReward tbSignInReward) {
        Page<TbSigninReward> pages;
        if (page != null && limit != null){
            pages = new Page<>(page, limit);
        }else {
            pages = new Page<>();
            pages.setSize(-1);
        }
        return baseMapper.selectPage(pages,new QueryWrapper<>(tbSignInReward));
    }
}
